package com.threadmethod.AtomicIntegerFieldUpdater;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
 * @PackageName:com.threadmethod.AtomicIntegerFieldUpdater
 * @ClassName:SubThread
 * @Description: 线程类
 * @Author: zhangxiaoyu
 * @date 2020/12/22 17:07
 */
public class SubThread extends Thread {

    //要更新的USER对象
    private User user;

    //创建更新器
    private AtomicIntegerFieldUpdater<User>  updater = AtomicIntegerFieldUpdater.newUpdater(User.class,"age");


    public SubThread(User user) {
        this.user = user;
    }

    @Override
    public void run() {
        //在子线程中对user对象自增10次
        for (int i=0;i<10;i++){
            System.out.println(updater.getAndIncrement(user));
        }
        
        
    }
}
